package com.kitty.common.utils;

import com.kitty.game.utils.Const;
import org.nutz.lang.util.NutMap;

import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class DecodeSendMessage {

    private final static List<String> bianyiList = Arrays.asList("伶俐鼠","帅帅猴","跳跳兔","蛋蛋鸡","威威虎","花花蛇","招财猪","溜溜马","咩咩羊","乖乖狗","笨笨牛","酷酷龙");
    private final static List<String> fabaoList = Arrays.asList("混元金斗","番天印","阴阳镜","定海珠","金蛟剪","九龙神火罩","卸甲金葫");
    private final static List<String> shenshouList = Arrays.asList("东山神灵","九尾狐","朱雀","勾陈","玄武","疆良");
    private final static List<String> guizuList = Arrays.asList("炼狱魔","阴阳师","魅灵","狱獒");
    private final static List<String> guijiangList = Arrays.asList("范无救","牛头狱卒","谢必安","马面罗刹");
    private final static List<String> guixianList = Arrays.asList("冥炎之灵","孟姑","谛听","阎摩");
    private final static List<String> qitaList = Arrays.asList("百年黑熊","血幻豪猪","赤血幼猿","魅影毒蝎");
    private final static List<String> gaojieList = Arrays.asList("跳跳虎","冥王凤凰","琉璃天马","疾风蚀日","至尊太极熊","北斗天蓬","九尾仙狐");
    private final static List<String> dijieList = Arrays.asList("仙葫芦","仙阳剑","墨麒麟","太极熊","筋斗云","北极熊","古鹿","玉豹","幻鹿","岳麓剑","赤焰葫芦");

    private final static List<String> xiangxingList = Arrays.asList("1","2","3","4","5");
    public static NutMap buildSendRewardMessage(String message){
        // 物品-盲盒-[最小值,最大值]
        // 奖励格式 按“-”分割
        String showName = "";
        String zhenName = "";
        String mailData = "#I%s|%s#r%s#I";
        NutMap buildRewardMessageMap = new NutMap();
        String[] messageList = message.split("-");
        //第一位 类型
        String type = messageList[0];
        String namePre =  messageList[1].trim();
        String paramPre = "";
        if(messageList.length>=3){
             paramPre = messageList[2].trim();
        }
        int rewardType = 0;
        if("物品".equals(type)){
            String itemName  = getParam(namePre,1);
            String itemCount = getParam(paramPre,2);
            mailData = String.format(mailData,type,itemName,itemCount);
            showName = itemName+"("+itemCount+")";
        }else if("宠物".equals(type) || "精怪".equals(type)) {
            String petType = namePre;
            String petName = paramPre;
            if("随机".equals(petName)){
                List<String> list = getList(petType);
                petName = getRandomParamByArray((String[]) list.toArray());
            }
            buildRewardMessageMap.put("petName",petName);
            mailData = String.format(mailData,"宠物",petName+"("+petType+")",1);
            showName = petType+"("+petName+")";
        }else if("法宝".equals(type)){
            String fabaoName = namePre;
            if("随机".equals(fabaoName)){
                List<String> list = getList(type);
                fabaoName = getRandomParamByArray((String[]) list.toArray());
            }
            String level = getParam(paramPre,2);
            String xiangxing = messageList[3];
            if("随机".equals(xiangxing)){
                List<String> list = getList("相性");
                xiangxing = getRandomParamByArray((String[]) list.toArray());
            }
            buildRewardMessageMap.put("polar",xiangxing);
            mailData = String.format(mailData,"物品",fabaoName,level);
            showName = "法宝("+fabaoName+level+"级)";
        }else if("首饰".equals(type)){
            // 首饰-千彩流光(2*x5+2*32灵+2*32敏)
//            String name = namePre.split("\\(")[0];
//            String value = namePre.split("\\(")[1].split("\\)")[0];
            mailData = String.format(mailData,type,namePre,1);
        }else if("积分".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "积分("+count+")";
        }else if("经验".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "经验("+count+")";
        }else if("道行".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "道行("+count+")";
        }else if("鬼气".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "鬼气("+count+")";
        }else if("武灵值".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,"武灵值",type,count);
            showName = "武灵值("+count+")";
        }else if("阴德".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "阴德("+count+")";
        }else if("金元宝".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "金元宝("+count+")";
        }else if("银元宝".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "银元宝("+count+")";
        }else if("金币".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "金币("+count+")";
        }else if("洛书经验".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "洛书经验("+count+")";
        }else if("称号".equals(type)){
            String name = namePre;
            buildRewardMessageMap.put("chenghaoName",name);
            mailData = String.format(mailData,type,name,1);
            showName = "称号（"+name+"）";
        }else if("奇门积分".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "奇门积分("+count+")";
        }else if("好心值".equals(type)){
            String count =  getParam(namePre,2);
            mailData = String.format(mailData,type,type,count);
            showName = "好心值("+count+")";
        }
        switch (type){
            case "金元宝":
                rewardType= Const.rewardJinyuanbao;
                break;
            case "银元宝":
                rewardType= Const.rewardYinyuanbao;
                break;
            case "金币":
                rewardType= Const.mailMoney;
                break;
            case "物品":
                rewardType= Const.rewardWupin;
                break;
            case "首饰":
                rewardType= Const.rewardShoushi;
                break;
            case "法宝":
                rewardType= Const.rewardFabao;
                break;
            case "宠物":
                rewardType = Const.rewardChongwu;
                break;
            case "精怪":
                rewardType= Const.rewardJingguai;
                break;
            case "积分":
                rewardType= Const.rewardJifen;
                break;
            case "奇门积分":
                rewardType= Const.rewardqimenJifen;
                break;
            case "好心值":
                rewardType= Const.rewardhaoxinzhi;
                break;
            case "鬼气":
                rewardType= Const.rewardGuiqi;
                break;
            case "武灵值":
                rewardType= Const.rewardWuhun;
                break;
            case "阴德":
                rewardType= Const.rewardYinde;
                break;
            case "洛书经验":
                rewardType= Const.rewardLuoshu;
                break;
            case "魂器":
                rewardType= Const.rewardHunqi;
                break;
            case "魂窍":
                rewardType= Const.rewardHunqiao;
                break;
            case "称号":
                rewardType= Const.rewardChenghao;
                break;
            case "经验":
                rewardType= Const.rewardJingYan;
                break;
            case "道行":
                rewardType= Const.rewardTao;
                break;
        }
        buildRewardMessageMap.put("type",rewardType);
        buildRewardMessageMap.put("data",mailData);
        buildRewardMessageMap.put("showName",showName);
        return buildRewardMessageMap;
    }
    private static List<String> getList(String type){
        switch (type){
            case "变异":
                return bianyiList;
            case "神兽":
                return shenshouList;
            case "其他":
                return qitaList;
            case "法宝":
                return fabaoList;
            case "鬼卒":
                return guizuList;
            case "鬼将":
                return guijiangList;
            case "鬼仙":
                return guixianList;
            case "高阶":
                return gaojieList;
            case "低阶":
                return dijieList;
            case "相性":
                return xiangxingList;
        }
        return new ArrayList<>();
    }
    public static String getParam(String namePre,int type){
        String param = "";
        if(namePre.startsWith("[") && namePre.endsWith("]")){
            namePre =  namePre.substring(1,namePre.length()-1);
            String[] namePres = namePre.split(",");
            if(type == 1){
                param = getRandomParamByArray(namePres);
            }else{
                param = getRegionParamByArray(namePres);
            }
        }else{
            param = namePre;
        }
        return param;
    }
    private static String getRandomParamByArray(String[] namePres){
        int index = ThreadLocalRandom.current().nextInt(namePres.length);
        return namePres[index];
    }
    private static String getRegionParamByArray(String[] namePres){
        int count = 0;
        if(namePres.length>=2){
            int minValue = Integer.parseInt(namePres[0]);
            int maxValue = Integer.parseInt(namePres[1]);
            if (minValue == maxValue) {
                count = maxValue;
            } else {
                count = ThreadLocalRandom.current().nextInt(minValue, maxValue + 1);
            }
        }else{
            count = Integer.parseInt(namePres[0]);
        }

        return String.valueOf(count);
    }

    public static void main(String[] args) {
        String a = "物品-盲盒-[1,5]";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "物品-[盲盒,超级女娲石]-[1,5]";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "宠物-变异-花花蛇";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "宠物-神兽-随机";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "精怪-高阶-太极熊";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "精怪-高阶-随机";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "法宝-定海珠-[7,7]-4";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "法宝-随机-[1,24]-随机";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "积分-[100,200]";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "首饰-千彩流光(2*x5+2*32灵+2*32敏)";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
        a = "金元宝-[100,200]";
        System.out.println("解析前："+a+"   解析后："+DecodeSendMessage.buildSendRewardMessage(a).toString());
    }

//    public static void main(String[] args) {
//        String a = "#I宠物|朱雀(神兽)$1$0#I";
//        System.out.println(DecodeSendMessage.SendMessageToHashMap(a).toString());
//        String b = "#I物品|羽化丹$1$0#I";
//        System.out.println(DecodeSendMessage.SendMessageToHashMap(b).toString());
//        String c ="#I首饰|岚金火链(2*x5+2*32灵+2*32敏)$1$0#I";
//        System.out.println(DecodeSendMessage.SendMessageToHashMap(c).toString());
//        String d= "2022-03-15 16:59:59";
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String now = sdf.format(new Date());
//
//        if(now.compareTo(d) >= 0 && "0".equals("0")){
//            System.out.println("------------------------");
//        }
//        Map map = new HashMap();
//        map.put("1","2");
//        String e = 0+1+"";
//        System.out.println(map.get(e));
//
//    }
}
